package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import biz.ShoppingCartBiz;
import biz.impl.ShoppingCartBizImpl;
import entity.ShoppingCart;

/**
 * Servlet implementation class ShoppingCarDeleteServlet
 */
@WebServlet("/ShoppingCarDelete.html")
public class ShoppingCarDeleteServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
     
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String rateIdStr = request.getParameter("rateId");
		int rateId=0;
		if(rateIdStr!=null&&!rateIdStr.isEmpty()){
			rateId=Integer.valueOf(rateIdStr);
			
			ShoppingCart cart = (ShoppingCart)request.getSession().getAttribute("shoppingCarList");
			ShoppingCartBiz cartBiz = new ShoppingCartBizImpl();
			cartBiz.removeCartItem(cart, rateId);
			
			HttpSession session = request.getSession();
			session.setAttribute("shoppingCarList", cart);
			session.setMaxInactiveInterval(86400);
			//返回原本的进入servlet路径
			response.sendRedirect(request.getHeader("referer"));
		}
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
